const express=require('express')
const pool=require('./pool')
const router=express.Router()
//用户登录接口
//http://127.0.0.1:9090/user/login
//rose_user数据表    unames upwd
router.post('/login',(req,res,next)=>{
    //console.log('7行检查登录接口连接成功')
    let obj=req.body
    //console.log(obj)
    pool.query('select * from rose_user where upwd=? and unames=?',[obj.upwd,obj.unames],(err,data)=>{
        console.log(data)
        if(err){next(err);return;}
        if(data.length==1){
          res.send({
            "code":1,
            "msg":"登录成功",
            "data":data[0]
          })
        }else{
          res.send({
              "code":0,
              "msg":"用户名或密码错误,登录失败"
          })
        }
      })
})

//用户注册接口
//rose_user数据表    unames upwd phone
router.post('/reg',(req,res,next)=>{
  //console.log('29行检查登录接口连接成功')
  let obj=req.body
  console.log(obj)
  pool.query(`insert into rose_user set ?`,[obj],(err,data)=>{
      console.log(data)
      if(err){next(err);return;}
        res.send({
          "code":1,
          "msg":"注册成功",
          "data":obj
      })
    })
})   
module.exports=router